package com.zhoux.others;

import java.util.Random;
import static java.lang.System.out;

/**
 * @author taoyi
 * @version 1.0
 * @date 2021/3/9 19:46
 */
public class FinalStaticData {
    private static Random random = new Random(); // 实例化一个Random类对象
    // 随机产生0~10之间的随机数，赋予定义为final的a1
    private final int a1 = random.nextInt(10);
    // 随机产生0~10之间的随机数，赋予定义为static final 的 a2
    private static final int a2 = random.nextInt(10);

    public static void main(String[] args) {
        FinalStaticData finalStaticData = new FinalStaticData(); // 实例化一个对象
        out.println("重新实例化对象调用a1的值："+finalStaticData.a1); // 调用定义为final的a1
        out.println("重新实例化对象调用a2的值："+finalStaticData.a2); // 调用定义为static final的a2
        FinalStaticData finalStaticData2 = new FinalStaticData(); // 实例化另一个对象
        out.println("重新实例化对象调用a1的值:" +finalStaticData2.a1);
        out.println("重新实例化对象调用a2的值:"+finalStaticData2.a2);
    }

}

